<template>
  <div class="home">
    <van-nav-bar
      :title="this.deviceInfo.devicename + '设置'"
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="home-content">
      <van-cell
        class="home-content-cell"
        center
        size="large"
        title="摄像头开关"
      >
        <template #right-icon>
          <van-switch
            v-model="camera.cameraState"
            size="24px"
            @change="onChange()"
          />
        </template>
      </van-cell>
      <van-field
        v-if="camera.cameraState"
        class="home-content-cell"
        v-model="camera.cameraIP"
        type="text"
        size="large"
        input-align="right"
        label-width="100px"
        label="摄像头IP地址"
      />
      <van-button round block type="info" @click="onSave">保存设置</van-button>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";

export default {
  name: "interface_page_settings",
  components: {},
  activated: function(){
    this.initInterface();
  },
  mounted: function () {
    this.initInterface();
    this.camera = JSON.parse(localStorage.getItem(this.$route.params.id));
    console.log(this.camera);
  },
  data: function () {
    return {
      camera: {
        cameraIP: "",
        cameraState: false,
      },
      paramsRes: "",
      show: false,
      columns: ["步行", "短跑", "长跑", "慢跑"],
      stepShow: false,
      deviceInfo: {},
    };
  },
  methods: {
    initInterface() {
      this.paramsRes = this.$route.params;
      this.deviceInfo = this.paramsRes.deviceInfo;
      var id = this.deviceInfo.id
      this.camera = JSON.parse(localStorage.getItem(id));
    },
    onConfirm(cdata) {
      this.cdata = cdata;
      localStorage.setItem("cdata", this.cdata);
      this.show = false;
    },
    onSave() {
      Toast({
        message: "设置保存成功",
        position: "bottom",
      });
      console.log("摄像头ID"+this.deviceInfo.id)
      localStorage.setItem(this.deviceInfo.id, JSON.stringify(this.camera));
      this.$router.back();
    },
    onClickLeft() {
      //this.$route.params.user = "123";
      // localStorage.setItem(this.deviceInfo.id, JSON.stringify(this.camera));
      this.$router.back();

      //console.log(localStorage.getItem(this.$route.params.id))

      // this.$router.push({
      //   name: "interface_page_info",
      //   params: {
      //     id: this.$route.params.id,
      //     name: this.$route.params.name,
      //     pub: this.$route.params.pub,
      //     sub: this.$route.params.sub,
      //     resData: this.$route.params.resData,
      //     cData: this.$route.params.cData,
      //     deviceInfo: this.$route.deviceInfo,
      //     routerType: "back",
      //   },
      // });
    },
  },
};
</script>

<style lang="scss" scoped>
.v-enter,
.v-leave-to {
  opacity: 0;
  transform: translateX(100px);
}

.v-enter-active,
.v-leave-to {
  transition: all 0.6s ease;
}

/* v-move 和 v-leave-to 配合使用，能够实现列表后续的元素，逐渐飘上来的效果 */
.v-move {
  transition: all 0.6s ease;
}

.v-leave-to {
  position: absolute;
}
.home {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: auto;
  display: flex;
  flex-flow: column;

  &-content {
    height: 100%;
    margin: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: left;
    justify-content: left;
    transition: 0.3s;
    overflow: auto;
    &-cell {
      margin: 0 0 10px 0;
      width: auto;
      border-radius: 10px;
      background-color: rgba(255, 255, 255, 0.85);
      backdrop-filter: blur(20px) saturate(180%);
    }
    &-control {
      border-radius: 20px;
      margin-top: 0px;
      margin-left: 20px;
      margin-right: 20px;
      margin-bottom: 60px;
    }
    &-area {
      &-text {
        margin-left: 20px;
        font-size: 5vw;
        color: white;
        font-weight: 900;
      }
    }
    &-text {
      margin: px2rem(20);
      font-size: px2rem(30);
      color: white;
      font-weight: 600;
      margin-bottom: px2rem(30);
    }
    &-shebei {
      margin-left: px2rem(20);
      margin-bottom: px2rem(5);
      font-size: px2rem(14);
      color: white;
      font-weight: 400;
    }
    &-info {
      transition: 0.5s;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      padding: 0 16px 15px;
      &-item {
        transition: 0.5s;
        margin: 5px;
        text-align: center;
        padding: 5px;
        border-radius: 20px 20px 20px 20px;
        // box-shadow: 0 0 16px 0 rgba(0, 0, 0, 0.3);
        width: calc(50% - 20px);
        height: calc(50% - 10px);
        display: flex;
        position: relative;
        flex-direction: column;
        justify-content: left;
        background-color: rgba(255, 255, 255, 0.9);
        background-attachment: fixed;
        &-title {
          display: flex;
          flex-direction: row;
          align-items: center;

          &-name {
            margin: auto;
            transition: 0.5s;
            text-align: left;
            color: black;
            //margin-top: 0;
            font-size: 4vw;
          }
        }

        &-data {
          transition: 0.5s;
          // text-align: right;
          color: black;
          margin: auto;
          font-size: 10vw;
          font-weight: 500;
        }
      }
    }
  }
}
.custom-button {
  width: auto;
  padding: 5px 10px;
  color: #fff;
  font-size: 4vw;
  line-height: 5vw;
  text-align: center;
  background-color: #0aadee;
  border-radius: 20px;
}
</style>
